import { QuestDefaultApi } from '@/library/util/api';
import { defaultErrorHandler } from '@/library/util/error-handler';
import { defineStore } from 'pinia';
import { QuestType } from './types/QuestType';
interface QuestTypeChoseState {
  /**  */
  types: QuestType[];

  selectType: QuestType;
}

export const useQuestTypeChoseStore = defineStore({
  id: 'QuestTypeChoseStore',
  state: (): QuestTypeChoseState => ({
    types: [],
    selectType: new QuestType(),
  }),
  actions: {
    /**
     * 获取问卷类型
     */
    async getCreateType() {
      try {
        const result = await QuestDefaultApi.questionaireTypeTypeListGet();
        if (result) {
          this.types = result;
        }
      } catch (error) {
        defaultErrorHandler(error);
      }
    },

    /**
     * 设置选择的类型
     * @param value
     */
    setSelectType(value: QuestTypeChoseState['selectType']) {
      this.selectType = value;
    },
  },
});
